$(function ($) {

    // 判断是否存在cookie，不存在就跳转到登录界面
    let username = getCookie()

    if (!username.login) {
        location.href = './login.html';
    }
    // 将登录的用户名渲染到头像下面
    // console.log($('.right h1').html());
    $('.left .user').append($(`<div class="img" style="border: 1px solid rgb(204, 204, 204); width: 100px; height: 100px; background-size: contain; background-repeat: no-repeat; background-position: center center;"></div>
                <div class="name">${username.login}</div>`))
    userT()

    function userT() {
        $.ajax({
            url: '/ap/getInformationImg.php',
            method: "post",
            data: {
                userId: username.login,


            },

            success(r) {

                let res = JSON.parse(r)
                //   console.log($('#test-image-preview'));
                $('.img').css({
                    backgroundImage: `url(${res[0].userimg})`
                })

                //   res.map(function(item){
                //       console.log(item.userimg);
                //       return $('#test-image-preview').css({backgroundImage:`url(${item.userimg})`})
                //   })



            }
        })
    }
    $('.header').on('click', '.tuichu', function () {
        // 引入的js.cookie.min.js里面的一些封装好的方法
        Cookies.remove('login')
        let username = getCookie()
        // 点击退出跳转到登录页面
        if (!username.login) {
            location.href = '../html/login.html';
        }
    })
    // 点击添加一行
    $('.right').on('click', '.add_row', function () {
        let res = $(`<tr class="add_tr">
    <td class="xuhao" contenteditable="true"></td>
    <td class="jiafen"></td>
    <td class="jianfen"></td>
    <td class="de"></td>
    <td class="zhi"></td>
    <td class="ti"></td>
    </tr>`)
        // let r=$('.add_tr').after(res)
        // res.insertAfter($('.add_tr')).siblings().removeClass('add_tr')
        res.appendTo($('.one tbody'))
        $('.one td').attr('contenteditable', 'true').css({
            wordBreak: "break-all"
        })
    })
    // 左边菜单收起
    $('li').next('.nav').slideUp()
    $('li').next('.hostory').slideUp()
    $('li').next('.guize').slideUp()
    $('li').on('click', function () {
        // 点击左边菜单高亮效果
        $(this).addClass('active').siblings().removeClass('active')
        // 判断下一个兄弟元素
        if ($(this).next().hasClass('nav')) {
            $(this).next('.nav').slideToggle()
        } else {
            $('li').next('.nav').slideUp()
        }
        if ($(this).next().hasClass('hostory')) {
            $(this).next('.hostory').slideToggle()
        } else {
            $('li').next('.hostory').slideUp()
        }
        if ($(this).next().hasClass('guize')) {
            $(this).next('.guize').slideToggle()
        } else {
            $('li').next('.guize').slideUp()
        }
        $(this).css({
            boxShadow: '1px 1px 5px 0px rgb(124, 124, 124)'
        }).siblings().css({
            boxShadow: 'none'
        })
    })
    // 点击二级菜单
    $('.left .nav p').on('click', function () {
        $(this).addClass('active').siblings().removeClass('active')
        // if ($(this).hasClass('dasi')) {
        //     $('.right').css({
        //         display: "none"
        //     })
        //     return
        // }
        // $('.right').css({
        //     display: "block"
        // })
        // 获取一张新的表格
        $('.right').css({
            display: "block"
        }).html(`<div class="top">
        <h1>玉林师范学院<span class="xueyuan">xxx学院</span><span class="collegeClass">xxx班</span>学生<span class="writTime">2021-2022</span>学年度第<span class="order">xxx</span>学期德智体综合测评量化评分表</h1>
        <p class="u_name">
            <span>
                <label for="">姓名：</label>
                <input id="username" type="text">
            </span>
            <span>
                <label for="">学号：</label>
                <input id="user_id" type="text">
            </span>
            <span>
            <label for="">大几：</label>
            <input id="grade" type="text">
        </span>
        </p>
        <button class="add_row">添加一行</button>
        </div>
        
        <table class="one">
        <thead>
            <tr>
                <th>序号</th>
                <th>加分及原因</th>
                <th>减分及原因</th>
                <th>德</th>
                <th>智</th>
                <th>体</th>
            </tr>
        
        </thead>
        <tbody>
            <tr class="add_tr">
                <td class="xuhao" contenteditable="true"></td>
                <td class="jiafen"></td>
                <td class="jianfen"></td>
                <td class="de"></td>
                <td class="zhi"></td>
                <td class="ti"></td>
            </tr>
        </tbody>
        </table>
        <table class="two">
        <tbody>
            <tr class="Score">
                <td>
                    <span>德育基本分</span>
                    <span contenteditable="true" id="deyuJBF" class="fenshu"></span>
                </td>
                <td>
                    <span>德育得分</span>
                    <span contenteditable="true" id="deyuDF" class="fenshu"></span>
                </td>
                <td>
                    <span>德育总分</span>
                    <span contenteditable="true" id="deyuZF" class="fenshu"></span>
                </td>
                <td>
                    <span>智育基本分</span>
                    <span contenteditable="true" id="zhiyuJBF" class="fenshu"></span>
                </td>
                <td>
                    <span>智育得分</span>
                    <span contenteditable="true" id="zhiyuDF" class="fenshu"></span>
                </td>
                <td>
                    <span>智育总分</span>
                    <span contenteditable="true" id="zhiyuZF" class="fenshu"></span>
                </td>
                <td>
                    <span>体育基本分</span>
                    <span contenteditable="true" id="tiyuJBF" class="fenshu"></span>
                </td>
                <td>
                    <span>体育得分</span>
                    <span contenteditable="true" id="tiyuDF" class="fenshu"></span>
                </td>
                <td>
                    <span>体育总分</span>
                    <span contenteditable="true" id="tiyuZF" class="fenshu"></span>
                </td>
            </tr>
            <tr class="Rink">
                <td colspan="2">
                    <span>综合测评总分</span>
                    <span contenteditable="true" id="cepingZF" class="rink"></span>
                </td>
                <td colspan="2">
                    <span>综合测评总分在班中名次</span>
                    <span contenteditable="true" id="cepingRink" class="rink">无</span>
                </td>
                <td>
                    <span>班长签名</span>
                    <span contenteditable="true" id="banzhang" class="rink"></span>
                </td>
                <td colspan="2">
                    <span>班主任签名</span>
                    <span contenteditable="true" id="banzhuren" class="rink"></span>
                </td>
                <td colspan="2">
                    <span>辅导员签名</span>
                    <span contenteditable="true" id="fudaoyuan" class="rink"></span>
                </td>
            </tr>
        </tbody>
        <tfoot>
            <tr>
                <td colspan="3">此表一式一份由二级学院保存备查。</td>
                <td><b>涂改无效</b> </td>
                <td><b>注意保存</b> </td>
                <td colspan="3">玉林师范学院学生工作部（处）制</td>
                <td class="time"></td>
            </tr>
        </tfoot>
        
        </table>
        <div class="bottom">
        <span>本学期必修课程名称及成绩分数:</span>
        <p class="project" contenteditable="true"></p>
        </div>
        <div class="stu">
        
        </div>
        <!-- <p class="status"></p> -->
        <div class="tijiao">
        <button class="jisuan">计算分数</button>
        <button class="updata">修改数据</button>
        <!-- <button class="baocun">保存数据</button> -->
        <button class="submit">提交数据</button>
            </div>`)
        ab()

        // 让表格里面的单元格用户可编辑
        $('.one td').attr('contenteditable', 'true').css({
            // 让单元格里面的内容自动换行
            wordBreak: "break-all"
        })
        // 表格顶部标题可编辑
        $('.right h1 .xueyuan').attr('contenteditable', 'true')
        $('.right h1 .collegeClass').attr('contenteditable', 'true')
        $('.right h1 .writTime').attr('contenteditable', 'true')
        $('.right h1 .order').attr('contenteditable', 'true')

    })
    // let arr = [];
    ab()
    // 封装点击事件函数
    function ab() {
        let arr = [];

        $('.tijiao').on('click', '.jisuan', function () {
            arr = []
            $.huoqu()

        })

        $.extend({
            huoqu: function () {
                $('.one tbody tr').each(function () { // 遍历 tr
                    let obj = {}
                    $(this).children('td').each(function () { // 遍历 tr 的各个 td
                        // 将的到的每一个td的值存入到对象
                        obj[$(this).attr('class')] = $(this).html();
                    });
                    // 将对象存入到数组
                    arr.push(obj)
                });
                // 对表格的分数进行计算
                let d = 0
                let z = 0
                let t = 0
                arr.forEach(function (item) {
                    item.de != '' ? item.de : item.de = 0;
                    item.zhi != '' ? item.zhi : item.zhi = 0;
                    item.ti != '' ? item.ti : item.ti = 0;
                    d = d + '+' + item.de
                    z = z + '+' + item.zhi
                    t = t + '+' + item.ti
                })

                $('.two .fenshu').eq(1).html(eval(d))
                $('.two .fenshu').eq(4).html(eval(z))
                $('.two .fenshu').eq(7).html(eval(t))
                $(this).attr('disabled', 'true')

                $('.two .fenshu').eq(2).html($('.two .fenshu').eq(2).html() != '' ? eval($('.two .fenshu').eq(2).html()).toFixed(2) : $('.two .fenshu').eq(2).html(''))
                $('.two .fenshu').eq(5).html($('.two .fenshu').eq(5).html() != '' ? eval($('.two .fenshu').eq(5).html()).toFixed(2) : $('.two .fenshu').eq(5).html(''))
                $('.two .fenshu').eq(8).html($('.two .fenshu').eq(8).html() != '' ? eval($('.two .fenshu').eq(8).html()).toFixed(2) : $('.two .fenshu').eq(8).html(''))

                $('.two .rink').eq(0).html(eval(`${$('.two .fenshu').eq(2).html() != '' ? $('.two .fenshu').eq(2).html() : '0'}+` + `${$('.two .fenshu').eq(5).html() != '' ? $('.two .fenshu').eq(5).html() : '0'}+` + `${$('.two .fenshu').eq(8).html() != '' ? $('.two .fenshu').eq(8).html() : '0'}`).toFixed(2))
                // console.log(`${$('.two .fenshu').eq(2).html() != '' ? $('.two .fenshu').eq(2).html() : '0'}+`+`${$('.two .fenshu').eq(5).html() != '' ? $('.two .fenshu').eq(5).html() : '0'}+`+`${$('.two .fenshu').eq(8).html() != '' ? $('.two .fenshu').eq(8).html() : '0'}`) ;

                $('.two tbody tr').each(function () { // 遍历 tr
                    // 将计算好的分数获取出来存入到数组
                    let objScore = {}
                    $(this).children('td').children('.fenshu').each(function () { // 遍历 tr 的各个 td

                        if ($(this).attr('id')) {

                            objScore[$(this).attr('id')] = $(this).html();
                        }


                    });

                    arr.push(objScore)
                    let objRink = {}
                    $(this).children('td').children('.rink').each(function () { // 遍历 tr 的各个 td
                        if ($(this).attr('id')) {
                            objRink[$(this).attr('id')] = $(this).html();
                        }
                        // objRink[$(this).attr('id')] = $(this).html();

                    });
                    arr.push(objRink)

                    // console.log($(this).children('td').children('.fenshu').hasClass('.fenshu'));
                    // if($(this).children().hasClass('.fenshu')){
                    //     console.log(1);
                    // }
                    // console.log($(this).children('.fenshu'));
                    // objScore[$(this).children('.fenshu').attr('id')] = $(this).children('.fenshu').html();
                    // arr.push(objScore)

                });

            }
        })

        // 点击提交数据时把数据传递给后端
        $('.tijiao').on('click', '.submit', function () {

            confirm('确定提交数据吗')
            // $(`<p title="${$('.right h1').html()}"></p>`).appendTo($('.hostory')).html($('.right h1').html())
            // 提交后单元格无法编辑
            $(this).attr('disabled', 'true')
            $('.one td').attr('contenteditable', 'false')
            $('.two .fenshu').attr('contenteditable', 'false')
            $('.two .rink').attr('contenteditable', 'false')
            let time = new Date()
            // 获取提交的时间
            time = formatDate(time)
            // console.log(time.year);
            $('.time').html(`${time.year+"年"+time.month+'月'+time.date+'日'}`)
            let Obj = {
                title: `玉林师范学院${$('.right h1 .xueyuan').html()}${$('.right h1 .collegeClass').html()}学生${$('.right h1 .writTime').html()}学年度第${$('.right h1 .order').html()}学期德智体综合测评量化评分表`,
                // collge:$('.right h1 .xueyuan').html(),
                // collgeClass:$('.right h1 .collgeClass').html(),
                // title:$('.right h1').html(),
                time: $('.time').html(),
                project: $('.project').html(),

            }
            arr.push(Obj)
            // 提交后数据的状态
            $('.status').html('待审核...')
            // console.log(arr);
            // 获取cookie,传给后端找到对应该用户的数据进行判断
            let login = getCookie('login') * 1

            // $.post(
            //     "/ap/adddata.php", {
            //         username: $('#username').val(),
            //         sid: login,
            //         status: '待审核...',
            //         // table:  JSON.stringify(arr)
            //         table:arr

            //     },
            //     function (res) {},
            //     "json"
            // );
            // console.log($('.right h1 .collegeClass').html());
            $.ajax({
                url: "/ap/adddata.php",
                method: "post",
                data: {
                    username: $('#username').val(),
                    sid: login,
                    status: '待审核...',
                    college: $('.right h1 .xueyuan').html(),
                    collegeClass: $('.right h1 .collegeClass').html(),
                    writTime: $('.right h1 .writTime').html(),
                    order: $('.right h1 .order').html(),
                    table: JSON.stringify(arr),
                    grade: $('#grade').val()

                },
                dataType: "json",
                async: false,
                success: function (res) {
                    console.log(res);
                    //success这个函数中 this指向 ajax对象
                    // console.log(this);
                },
                error: function (err) {
                    console.log(err);
                },

            });

            // request()
            a()
        })
        // 点击修改按钮
        $('.tijiao').on('click', '.updata', function () {
            // console.log(arr);
            arr = []
            let r = confirm('确定修改数据吗')
            // console.log(confirm());
            if (!r) {
                return
            }
            $.huoqu()
            // 让表格重新可以编辑
            $('.one td').attr('contenteditable', 'true')
            $('.two .fenshu').attr('contenteditable', 'true')
            $('.two .rink').attr('contenteditable', 'true')
            $('.right h1 .xueyuan').attr('contenteditable', 'true')
            $('.right h1 .collegeClass').attr('contenteditable', 'true')
            $('.right h1 .writTime').attr('contenteditable', 'true')
            $('.right h1 .order').attr('contenteditable', 'true')
            $('.u_name input ').removeAttr('disabled')
            $('.add_row').removeAttr('disabled')
            $(this).prev().removeAttr('disabled')
            // 点击修改数据时，将提交数据按钮重新添加一个class名
            $('.submit').removeAttr('disabled').removeClass('submit').addClass('submit2').on('click', function () {
                // 判断弹窗是true还是false
                let r = confirm('确定提交数据吗')
                if (!r) {
                    return
                }
                // 再次提交再次获取提交时间
                let time = new Date()

                time = formatDate(time)
                // console.log(time.year);
                $('.time').html(`${time.year+"年"+time.month+'月'+time.date+'日'}`)
                let Obj = {
                    title: `玉林师范学院${$('.right h1 .xueyuan').html()}${$('.right h1 .collegeClass').html()}学生${$('.right h1 .writTime').html()}学年度第${$('.right h1 .order').html()}学期德智体综合测评量化评分表`,
                    // title:$('.right h1').html(),
                    time: $('.time').html(),
                    project: $('.project').html()
                }
                arr.push(Obj)

                let login = getCookie('login') * 1

                // console.log($('.right h1 .order').html());
                // $.post(
                //     "/ap/updata.php", {
                //         username: $('#username').val(),
                //         sid: login,
                //         status: '待审核...',
                //         college: $('.right h1 .xueyuan').html(),
                //         collegeClass: $('.right h1 .collegeClass').html(),
                //         writTime:$('.right h1 .writTime').html(),
                //         order:$('.right h1 .order').html(),
                //         table: JSON.stringify(arr)

                //     },
                //     function (res) {

                //     },
                //     "json"
                // );
                $.ajax({
                    url: "/ap/updata.php",
                    method: "post",
                    data: {
                        username: $('#username').val(),
                        sid: login,
                        status: '待审核...',
                        college: $('.right h1 .xueyuan').html(),
                        collegeClass: $('.right h1 .collegeClass').html(),
                        writTime: $('.right h1 .writTime').html(),
                        order: $('.right h1 .order').html(),
                        table: JSON.stringify(arr),
                        grade: $('#grade').val()

                    },
                    dataType: "json",
                    async: false,
                    success: function (res) {
                        console.log(res);
                        //success这个函数中 this指向 ajax对象
                        // console.log(this);
                    },
                    error: function (err) {
                        console.log(err);
                    },

                });
            })

        })
    }
    a()
    // 获取数据
    function a() {
        // console.log();
        $.ajax({
            url: '/ap/gettitle.php',
            method: "post",
            data: {
                sid: username.login,
            },
            dataType: 'json',
            success(res) {
                // console.log(res);

                res.forEach(function (item) {
                    // console.log(item.table);
                    let data = JSON.parse(item.table)
                    // console.log(res);
                    // console.log(item.table);
                    // console.log(JSON.parse(item.table));
                    // console.log(res);
                    $.rander1(res)
                })
            }
        })
    }

    $.extend({
        rander1: function (data) {

            let r = data.map(function (item) {
                // ${item.title?`<p title="${item.title}">${item.title}</p>`:''}

                return `<p title="玉林师范学院${item.college}${item.class}学生${item.time}学年度第${item.order}学期德智体综合测评量化评分表"><button class="del">删除</button>玉林师范学院<span class="xueyuan">${item.college}</span><span class="collegeClass">${item.class}</span>学生<span class="writTime">${item.time}</span>学年度第<span class="order">${item.order}</span>学期德智体综合测评量化评分表</p>
                
            `
            }).join('')
            // let r=`玉林师范学院${$('.right h1 .xueyuan').html()}${$('.right h1 .collegeClass').html()}学生${$('.right h1 .writTime').html()}学年度第${$('.right h1 .order').html()}学期德智体综合测评量化评分表`
            $('.hostory').html(r)
            $('.left .hostory p').on('click', function () {

                $(this).addClass('active').siblings().removeClass('active')

                $('.right').css({
                    display: "block"
                })

                let writTime = $(this).children('.writTime').html()
                let order = $(this).children('.order').html()
                request(writTime, order);
                $.cepingRink($(this))
                return
            })
            $.del()
        },
        del: function () {

            $('.del').on('click', function (e) {
                e.stopPropagation()
                $(this).parent().remove()
                $.post(
                    "/ap/delTable.php", {
                        sid: username.login,
                        order: $(this).siblings('.order').html(),
                        writTime: $(this).siblings('.writTime').html(),
                        collegeClass: $(this).siblings('.collegeClass').html()


                    },
                    function (res) {
                        console.log(res);
                    },
                    "json"
                );

            })
        }

    })


    function request(writTime, order) {

        // let xhr = new XMLHttpRequest();

        // xhr.open("post", "/ap/getdata.php");

        // // post请求的参数写在 send() 括号中
        // // 还必须设置请求头 Content-Type
        // xhr.setRequestHeader(
        //     "Content-Type",
        //     "application/x-www-form-urlencoded"
        // );

        // xhr.send();
        // xhr.onload = function () {

        //     let res = JSON.parse(xhr.responseText)
        //     $.rander(res);

        //     res.forEach(function (item) {
        //        console.log(JSON.parse(item.table));

        //     })
        // };
        // console.log(writTime);
        $.ajax({
            url: '/ap/getdata.php',
            method: "post",
            data: {
                sid: username.login,
                time: writTime,
                order: order,

            },
            dataType: 'json',
            success(res) {
                // console.log(res);
                $.rander(res)

            }
        })
    }
    // 将获取到的数据进行渲染
    $.extend({
        rander: function (data) {
            let ran = data.map(function (item) {

                // let res = JSON.parse(item.table);
                return `<h1>玉林师范学院<span class="xueyuan">${item.college}</span><span class="collegeClass">${item.class}</span>学生<span class="writTime">${item.time}</span>学年度第<span class="order">${item.order}</span>学期德智体综合测评量化评分表</h1>`
                // return res.map(function (res) {
                //     // console.log(res);
                //     return `${res.title?`<h1>${res.title}</h1>`:''}`
                // }).join('')

            }).join('')



            let ran1 = data.map(function (item) {

                // let res = JSON.parse(item.table);


                return `<p class="u_name">
                    <span>
                        <label for="">姓名：</label>
                
                        <input id="username" type="text" value="${item.username}">
                    </span>
                    <span>
                        <label for="">学号：</label>
                        <input id="user_id" type="text" value="${item.s_id}">
                    </span>
                    <span>
                        <label for="">大几：</label>
                        <input id="grade" type="text" value="${item.grade}">
                    </span>
                
                </p>
                <button class="add_row">添加一行</button>
                `
            }).join('')
            $('.top').html(ran + ran1)
            let ran2 = data.map(function (item) {

                let res = JSON.parse(item.table);

                return res.map(function (res) {
                    // 用三目运算判断是否存在这个数据,存在就渲染
                    return `${res.xuhao?` <tr>
                        ${res.xuhao?`<td class="xuhao" contenteditable="true">${res.xuhao}</td>`:'<td class="xuhao" contenteditable="true"></td>'}
                        ${res.jiafen?`<td class="jiafen">${res.jiafen}</td>`:'<td class="jiafen"></td>'}
                        ${res.jianfen?`<td class="jianfen">${res.jianfen}</td>`:'<td class="jianfen"></td>'}
                        ${res.de?`<td class="de">${res.de}</td>`:'<td class="de"></td>'}
                        ${res.zhi?`<td class="zhi">${res.zhi}</td>`:'<td class="zhi"></td>'}
                        ${res.ti?`<td class="ti">${res.ti}</td>`:'<td class="ti"></td>'}  
                        </tr>`:''}
                `
                }).join('')

            }).join('')
            // console.log(ran2);
            $('.one tbody').html(ran2)

            let ran3 = data.map(function (item) {

                let res = JSON.parse(item.table);

                return res.map(function (res) {

                    return ` 
                    ${res.deyuJBF?`<td>
                    <span>德育基本分</span><span contenteditable="true" id="deyuJBF" class="fenshu">${res.deyuJBF}</span></td>`:''}
                    ${res.deyuDF?`<td>
                    <span>德育得分</span><span contenteditable="true" id="deyuDF" class="fenshu">${res.deyuDF}</span></td>`:''}
                    ${res.deyuZF?`<td>
                    <span>德育总分</span><span contenteditable="true" id="deyuZF" class="fenshu">${res.deyuZF}</span></td>`:''}
                    ${res.zhiyuJBF?`<td>
                    <span>智育基本分</span><span contenteditable="true" id="zhiyuJBF" class="fenshu">${res.zhiyuJBF}</span></td>`:''}
                    ${res.zhiyuDF?`<td>
                    <span>智育得分</span><span contenteditable="true" id="zhiyuDF" class="fenshu">${res.zhiyuDF}</span></td>`:''}
                    ${res.zhiyuZF?`<td>
                    <span>智育总分</span><span contenteditable="true" id="zhiyuZF" class="fenshu">${res.zhiyuZF}</span></td>`:''}
                    ${res.tiyuJBF?`<td>
                    <span>体育基本分</span><span contenteditable="true" id="tiyuJBF" class="fenshu">${res.tiyuJBF}</span></td>`:''}
                    ${res.tiyuDF?`<td>
                    <span>体育得分</span><span contenteditable="true" id="tiyuDF" class="fenshu">${res.tiyuDF}</span></td>`:''}
                    ${res.tiyuZF?`<td>
                    <span>体育总分</span><span contenteditable="true" id="tiyuZF" class="fenshu">${res.tiyuZF}</span></td>`:''}
                
                            
                        
                        
                           
                `
                }).join('')

            }).join('')
            // console.log(ran3);
            $('.Score').html(ran3)
            let ran4 = data.map(function (item) {

                let res = JSON.parse(item.table);

                return res.map(function (res) {

                    return `
                    ${res.cepingZF?`<td colspan="2">
                    <span>综合测评总分</span><span contenteditable="true" id="cepingZF" class="rink">${res.cepingZF}</span></td>`:``}
                
                            
                            
                    ${res.cepingRink?`<td colspan="2">
                    <span>综合测评总分在班中名次</span><span contenteditable="true" id="cepingRink" class="rink">${res.cepingRink}</span></td>`:''}
                
                            
                            
                    ${res.banzhang?`<td>
                    <span>班长签名</span><span contenteditable="true" id="banzhang" class="rink">${res.banzhang}</span></td>`:''}
                    
                            
                            
                    ${res.banzhuren?`<td colspan="2">
                    <span>班主任签名</span><span contenteditable="true" id="banzhuren" class="rink">${res.banzhuren}</span></td>`:''}
                
                            
                            
                    ${res.fudaoyuan?`<td colspan="2">
                    <span>辅导员签名</span><span contenteditable="true" id="fudaoyuan" class="rink">${res.fudaoyuan}</span></td>`:''}         
                `
                }).join('')

            }).join('')
            // console.log(ran4);
            $('.Rink').html(ran4)
            // console.log($('.hostory p'));


            let ran5 = data.map(function (item) {

                let res = JSON.parse(item.table);

                return `<td colspan="3">此表一式一份由二级学院保存备查。</td>
            <td><b>涂改无效</b> </td>
            <td><b>注意保存</b> </td>
            <td colspan="3">玉林师范学院学生工作部（处）制</td>${res.map(function (res) {
                
                return `
                ${res.time?`<td class="time">${res.time}</td>`:''}
                
                            
                `
            }).join('')}`

            }).join('')
            $('tfoot tr').html(ran5)
            // console.log(ran5);
            let ran6 = data.map(function (item) {

                let res = JSON.parse(item.table);

                return `<span>本学期必修课程名称及成绩分数:</span>${res.map(function (res) {

                return `${res.project?`<p class="project" contenteditable="true">${res.project}</p>`:''}`
            }).join('')}`

            }).join('')
            $('.bottom').html(ran6)
            let ran7 = data.map(function (item) {
                return `<p class="status">${item.status}</p>`

            }).join('')
            $('.stu').html(ran7)
            $.status()
            // 判断数据 的状态，如果是已通过，把表格的三个按钮变为不可点击
            if ($('.status').html() == '已通过') {
                $('.updata').attr('disabled', 'true')
                $('.hostory p').hover(function () {
                    $('.active').children('.del').css({
                        display: 'none'
                    })
                    // console.log($(this));
                })
            } else {
                $('.hostory p').hover(function () {
                    $('.active').children('.del').css({
                        display: 'inline-block'
                    })
                    // console.log($(this));
                }, function () {
                    $('.active').children('.del').css({
                        display: 'none'
                    })
                })
            }
            if ($('.status').html() == '不通过') {
                // 如果是不通过就把字体标红
                $('.status').css({
                    color: 'red'
                })

            }
            // 查看已提交的数据表时 ，表格不可编辑
            $('.one td').attr('contenteditable', 'false')
            $('.two .fenshu').attr('contenteditable', 'false')
            $('.two .rink').attr('contenteditable', 'false')
            $('.add_row').attr('disabled', 'true')
            $('.jisuan').attr('disabled', 'true')
            $('.submit').attr('disabled', 'true')
            $('.u_name input ').attr('disabled', 'true')
            // $('updata').on('click', function () {

            //     $('.jisuan').attr('disabled', 'false')
            //     $('.submit').attr('disabled', 'false')
            //     $('.u_name input ').attr('disabled', 'false')
            //     $('.add_row').attr('disabled', 'false')
            // })
        }

    })
    // 点击个人中心跳转到个人资料页面
    $('.information').on('click', function () {
        // console.log(username);
        location.href = '../html/information.html?' + username.login
    })

    // $('.pingfen')
    $.extend({
        cepingRink: function (ts) {
            // console.log($('active'));
            // console.log(ts.children('.order').html());
            $.extend({
                status: function () {
                    
                    if ($('.status').html()=='已通过') {
                        $.ajax({
                            url: '/ap/getcepingRink.php',
                            method: "post",
                            data: {

                                order: ts.children('.order').html(),
                                writTime: ts.children('.writTime').html(),
                                collegeClass: ts.children('.collegeClass').html(),
                                status:$('.status').html()

                            },
                            dataType: 'json',
                            success(rest) {
                                // console.log(rest);
                                // console.log($('#cepingRink').html());
                                $.cepingZF(rest)
                            }
                        })
                    }
                }
            })



        },

        cepingZF: function (data) {

            let ceping = {}
            // let cepingArr = []
            data.forEach(function (item) {

                let TB = JSON.parse(item.table)

                TB.forEach(function (ite) {

                    if (ite.cepingZF) {
                        // console.log(data.s_id);
                        ceping['A' + item.s_id] = ite.cepingZF
                        // cepingArr.push(ceping)


                    }

                })

            })
            // console.log(ceping);

            // console.log(Object.keys(ceping)[1]);
            function sort_object(obj) {
                let items = Object.keys(obj).map(function (key) {
                    return [key, obj[key]];
                });
                items.sort(function (first, second) {
                    return second[1] - first[1];
                });
                let sorted_obj = {}
                $.each(items, function (k, v) {
                    let use_key = v[0],
                        use_value = v[1];
                    sorted_obj[use_key] = use_value;
                })
                return (sorted_obj)
            }
            Object.keys(sort_object(ceping)).forEach(function (item, index) {

                // console.log(username.login);
                if ('A' + username.login === item) {

                    $('#cepingRink').html(`${index+1}`)

                }
            })
        }
    })
})